import { Component, OnInit } from '@angular/core';
import { Store } from '@ngxs/store';
import { AutoUnsubscribe } from 'ngx-auto-unsubscribe-decorator';
import { SystemAction, SystemSelector } from './store';
import { DemoAction, DemoSelector } from './store/demo';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
  @AutoUnsubscribe() isCollapsed$ = this.store.select(SystemSelector.isCollapsed);
  @AutoUnsubscribe() collapsedType$ = this.store.select(SystemSelector.collapsedType);
  @AutoUnsubscribe() list$ = this.store.select(DemoSelector.list);

  title = 'codeforfun-statistics';

  constructor(
      private store: Store,
  ) {
  }

  ngOnInit(): void {
    this.store.dispatch(new DemoAction.LoadMenu());
  }

  changeCollapsed() {
    this.store.dispatch(new SystemAction.ChangeCollapsed());
  }

}
